﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GestionePolveri2.DAL;
using GestionePolveriLib.BL;
using FrameworkLib.Facades;

namespace GestionePolveriLib.Facades 
{
    public class CausaliScaricoFacade : FacadeBase<GestionePolveriEntities>
    {
        public CausaliScaricoFacade()
        {

        }

        public CausaleScarico GetCausaleScarico(string codiceCausale)
        {
            CausaleScarico retValue = null;

            try
            {
                GestionePolveriEntities context = this.GetContext();
                var obj = from x in context.CausaliScarico
                          where x.CodCausaleScarico == codiceCausale
                          select new CausaleScarico
                          {
                              ID = x.IDCausaleScarico,
                              CodCausale = x.CodCausaleScarico,
                              Descrizione = x.Descrizione
                          };

                if (obj.Any())
                {
                    retValue = obj.FirstOrDefault();
                }
            }
            catch (Exception ex)
            {
                // throw;
            }

            return retValue;
        }

        public void LoadAsync(BackgroundWorkerCallbackBase.Callback callback)
        {
            this.RunAsync(() => GetAll(), callback);
        }
        public List<CausaleScarico> GetAll()
        {
            List<CausaleScarico> retValue = null;

            try
            {
                GestionePolveriEntities context = this.GetContext();
                var obj = from x in context.CausaliScarico
                          where x.CodCausaleScarico != "I"
                          select new CausaleScarico
                          {
                              ID = x.IDCausaleScarico,
                              CodCausale = x.CodCausaleScarico,
                              Descrizione = x.Descrizione,                              
                          };

                if (obj.Any())
                {
                    ComposizioneColoreFacadeExt ccf = new ComposizioneColoreFacadeExt();

                    retValue = obj.ToList();
                    
                }
            }
            catch (Exception ex)
            {
                // throw ex;
            }

            return retValue;
        }

        public List<CausaleScarico> GetAllI()
        {
            List<CausaleScarico> retValue = null;

            try
            {
                GestionePolveriEntities context = this.GetContext();
                var obj = from x in context.CausaliScarico                         
                          select new CausaleScarico
                          {
                              ID = x.IDCausaleScarico,
                              CodCausale = x.CodCausaleScarico,
                              Descrizione = x.Descrizione,
                          };

                if (obj.Any())
                {
                    ComposizioneColoreFacadeExt ccf = new ComposizioneColoreFacadeExt();

                    retValue = obj.ToList();

                }
            }
            catch (Exception ex)
            {
                // throw ex;
            }

            return retValue;
        }
    }
}
